package com.pepository.neo4j;

import com.model.WordInfo;
import com.model.neo4j.Role;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface WordRelationRepository extends Neo4jRepository<Role, Long> {

    @Query(
            "MERGE (parent:Word {word: :#{#parent.word} }) " +
            "SET parent.dbId = :#{#parent.id} " +
            "MERGE (child:Word {word: $childWord}) " +
            "MERGE (parent)<-[s:SYNONYMS]-(child) " +
            "SET s.dbId = $explainDetailId " +
            "return true"
    )
    boolean mergeSynonymsWord(@Param("parent") WordInfo parent,
                              @Param("explainDetailId") Long explainDetailId,
                              @Param("childWord") String childWord);

    @Query(
            "MERGE (parent:Word {word: :#{#parent.word} }) " +
            "SET parent.dbId = :#{#parent.id} " +
            "MERGE (child:Word {word: $childWord}) " +
            "MERGE (parent)<-[s:TYPE]-(child) " +
            "SET s.dbId = $explainDetailId " +
            "return true"
    )
    boolean mergeTypeWord(@Param("parent") WordInfo parent,
                              @Param("explainDetailId") Long explainDetailId,
                              @Param("childWord") String childWord);

    @Query(
            "MERGE (parent:Word {word: :#{#parent.word} }) " +
            "SET parent.dbId = :#{#parent.id} " +
            "MERGE (child:Word {word: $childWord}) " +
            "MERGE (parent)<-[:FAMILY]-(child) " +
            "return true"
    )
    boolean mergeFamilyWord(@Param("parent") WordInfo parent,
                          @Param("childWord") String childWord);


    @Query("match (w:$0 {word:$word}) return w is not null")
    boolean userHasWord( String userTable,@Param("word") String word);

}
